package com.alpha.core.serializer;

import com.alpha.core.utils.JsonUtil;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

/**
 * 字符串转对象Json序列化器
 *
 * @author chenruwan
 * @since 2022-01-01
 */
public class StringToObjectSerializer extends JsonSerializer<String> {
    @Override
    public void serialize(String value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        gen.writeObject(JsonUtil.fromString(value, Object.class));
    }
}
